<#include "layout/template.ftl"/>

<@htmlHead title="编辑优惠券">
</@htmlHead>


 
<@htmlBody 'coupon' 'couponManage'>

	<!-- breadcrumbs begin -->
	<#include "layout/breadcrumbs.ftl">
	<@breadcrumbs '优惠券管理' '编辑优惠券'></@breadcrumbs>
	<!-- breadcrumbs end -->

	<!-- page-content begin -->
	<div class="page-content">
			
			<!-- page-header begin -->
			<div class="page-header">
					<h1>
						编辑优惠券
					</h1>
			</div>
			<!-- page-header end -->

			<!-- page-body begin -->
			<div class="row">	
				<div class="col-md-8 col-md-offset-2">
				
						<!-- 表单开始 -->
						<form class="form-horizontal" id="validation-form" method="post" action="${path}/manage/coupon/coupon/update/${coupon.id}" >
							<fieldset>
								<input type="hidden" name="id" value="${coupon.id}">								
								<input type="hidden" name="id" value="${coupon.rule.id}">								
								<input type="hidden" name="status"  id="status" value="${coupon.status}" />			
								
							    <div class="form-group">
									<label class="control-label col-md-2 no-padding-right" for="name">名称:</label>
							
									<div class="col-md-10">
										<div class="clearfix">
											<input type="text" class="form-control" style="width:50%" placeholder="请输入名称" name="name"  id="name" value="${coupon.name}" />
										</div>
									</div>
								</div>
								
								<div class="form-group">
									<label class="control-label col-md-2 no-padding-right" for="name">数量:</label>
							
									<div class="col-md-10">
										<div class="clearfix">
											<#if coupon.status == 4>
												<input type="text" class="form-control"  style="width:50%" disabled="disabled"  placeholder="请输入数量" name="quantity"  id="quantity" value="${coupon.quantity}" readonly="true"/>  
											<#else>
												<input type="text" class="form-control"  style="width:50%" disabled="disabled"  placeholder="请输入数量" name="quantity"  id="quantity" value="${coupon.quantity}" />
											</#if>
										</div>
									</div>
								</div>
                                
                                <div class="form-group">
									<label class="control-label col-md-2 no-padding-right" for="name"></label>
									<div class="col-md-10">
										<div class="clearfix" style="color:#FF0000">
										 ------------------下面请填写批次规则-------------------                            
										</div>
									</div>
								</div>
								
								
								   <div class="form-group">
									<label class="control-label col-md-2 no-padding-right" for="name">模式:</label>
									<div class="col-md-10">
										<div class="clearfix">
											<#if  coupon.mode==1>
											<p class="form-control-static">纸质</p>
											<#else>
											<p class="form-control-static">完善地址发送</p>
											</#if>
										</div>
									</div>
								</div>
								
							    <div class="form-group">
									<label class="control-label col-md-2 no-padding-right" for="name">面值:</label>
									<div class="col-md-10">
										<div class="clearfix">
											<#if coupon.status == 4>
												<input type="text" class="form-control"  style="width:50%"  placeholder="请输入面值" disabled="disabled" name="rule.usageAmount"  id="usageAmount" value="${coupon.rule.usageAmount}" readonly="true"/>
											<#else>
												<input type="text" class="form-control"  style="width:50%"  placeholder="请输入面值" disabled="disabled" name="rule.usageAmount"  id="usageAmount" value="${coupon.rule.usageAmount}" />
											</#if>
										</div>
									</div>
								</div>
								
								 <div class="form-group">
									<label class="control-label col-md-2 no-padding-right" for="name">最小订单金额:</label>
							
									<div class="col-md-10">
										<div class="clearfix">
											<input type="text" class="form-control"  style="width:50%"  placeholder="请输入最小订单金额" name="rule.minAmount"  id="minAmount" value="${coupon.rule.minAmount}" />
										</div>
									</div>
								</div>
								
								<div class="form-group">
								    <label class="control-label col-md-2 no-padding-right" for="name">开始日期:</label>
							
									<div class="col-md-10">
										<div class="clearfix">
											<input type="text" class="input" id="startTime" name="rule.startTime" value="${coupon.rule.startTime}" /> 
										</div>
									</div>
								
                                </div>


                                <div class="form-group">
								   <label class="control-label col-md-2 no-padding-right" for="name">结束日期:</label>
							
									<div class="col-md-10">
										<div class="clearfix">
											<input type="text" class="input" id="endTime" name="rule.endTime" value="${coupon.rule.endTime}" /> 
										</div>
									</div>
								
                                </div>
                                
                                					

								
								
							</fieldset>
						</form>
						<!-- 表单结束 -->

						<!-- 提交开始 -->
	                    <div class="form-group">
	                    	<div class="col-md-8 center">
		                    	<button id="form-submit" type="button" onclick="mysubmit('validation-form')"  class="btn btn-primary">
									<i class="fa fa-save align-top bigger-125"></i>保存
								</button>
							 
								<button type="reset" class="btn">
									<i class="fa fa-pencil align-top bigger-125"></i>重置
								</button>
							</div>					
                   		</div>
						<!-- 提交结束  -->
				</div>
			</div>
			<!-- page-body end -->
		
	</div>		
	<!-- page-content end -->

</@htmlBody>



<@htmlBodyScript>
	
	<!-- 自定义属性 -->
	<script>

		
	    //提交表单
	 	function mysubmit(form){
	 		$("#"+form).submit();
	 	}
	</script>

 	 <!-- 日期控件-->
 	<script src="${resources}/plugins/bootstrap-datetimepicker/2.3.4/js/bootstrap-datetimepicker.js"></script>
   	<script src="${resources}/plugins/bootstrap-datetimepicker/2.3.4/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>	
	<script type="text/javascript">
		 $("#startTime,#endTime").datetimepicker({
				bootcssVer:3,
			   	format: "yyyy-mm-dd hh:ii:ss",
			    language:"zh-CN",
				weekStart: 1,
	        	todayBtn:  1,
				autoclose: 1,
				todayHighlight: 1,
				startView: 2,
				minView: 2,
				forceParse: 0
			});
    </script>


	<!-- 验证框架 -->	
	<script src="${resources}/plugins/jquery-validation/jquery.validate.min.js"></script>
	<script src="${resources}/plugins/jquery-validation/messages_zh.min.js"></script>
	<script type="text/javascript">
			jQuery.validator.addMethod("isName", function(value, element) {       
	 			var corpName =  /^[\u0391-\uFFE5\w\-\s\.]{1,50}$/;
  				 return this.optional(element) || corpName.test(value);       
 			}, "请使用汉字、英文字母、数字、下划线、减号、空格或点");   
 			
	
			$('#validation-form').validate({
				errorElement: 'div',
				errorClass: 'help-block',
				focusInvalid: false,
				rules: {
					name: {
						required:true,
						maxlength: 50,
						isName:true
					},
					quantity: {
						required:true,
						digits:true,
						max:1000000,
						min:1,
						number:true
						
					},
					"rule.usageAmount": {
						required:true,
						digits:true,
						max:500000,
						min:1,
						number:true
					},
					"rule.minAmount": {
						required:true,
						digits:true,
						max:500000,
						min:1,
						number:true
					},
					"rule.startTime": {
						required:true
					},
					"rule.endTime": {
						required:true
					}
					
				},
		
				messages: {
				},
		
		
				highlight: function (e) {
					$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
				},
		
				success: function (e) {
					$(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
					$(e).remove();
				},
		
				errorPlacement: function (error, element) {
					if(element.is('input[type=checkbox]') || element.is('input[type=radio]')) {
						var controls = element.closest('div[class*="col-"]');
						if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
						else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
					}
					else if(element.is('.select2')) {
						error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
					}
					else if(element.is('.chosen-select')) {
						error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
					}
					else error.insertAfter(element.parent());
				},
		
				submitHandler: function (form) {
				   
					form.submit();
				},
				invalidHandler: function (form) {
				}
			});
	</script>
</@htmlBodyScript>